//基础api地址
//var BASEURL = 'http://www.daydaycs.com';
//由于服务端跨域问题，本地启动一个nodeJs服务，来做请求转发
var BASEURL = '/api';

var url1 = 'http://www.daydaycs.com';
/*
* 工具类
* Api api接口
* Const 常量数据
* isNull 判断是否空 null, undefined
* request 发请求
*   params:  url(string) 请求地址  data(object) 请求数据  callback(function) 回调函数
* */
var Utils = {
	Api: {
		rptSubjectWareGet: '/rrj/Api/subjectWareGet', //主体仓库
		rptSYBGet : '/rrj/Api/rptSYBGet', //损益表
		rptSFZSYBGet: '/rrj/Api/rptSFZSYBGet', //收付制损益表
		rptXJLLBGet: '/rrj/Api/rptXJLLBGet', //现金流量表
		rptZCFZBGet: '/rrj/Api/rptZCFZBGet', //资产负债表
		rptMgntHbzj: '/rrj/Api/rptMgntHbzj',//账户资金余额表
		rptMgntHbzjDetail: '/rrj/Api/rptMgntHbzjDetail',//账户资金余额明细
		rptWlGet: '/rrj/Api/rptWlGet', //往来报表
		rptWlDetail: '/rrj/Api/rptWlDetail', //往来明细
		rptHbzjGet: '/rrj/Api/rptHbzjGet', //账号资源余额表
		rptHbzjDetail: '/rrj/Api/rptHbzjDetail',//账号资源余额明细
		rptMgntKcGet: '/rrj/Api/rptMgntKcGet', //库存表
		rptMgntKcDetail: '/rrj/Api/rptMgntKcDetail', //库存表明细
		ioMainInitInfo: '/rrj/Api/ioMainInitInfo', //进出单创建初始化数据
		ioMainGet: '/rrj/IoMain/ioMainGet', //进出单创建  todo
		ioTypeGet: '/rrj/IoType/ioTypeGet', //进出单类型  todo
		ioTypeAdd: '/rrj/IoType/ioTypeAdd', //新增进出单  todo
		ioTypeEdt: '/rrj/IoType/ioTypeEdt', //编辑进出单  todo
		ioTypeDel: '/rrj/IoType/ioTypeDel', //删除进出单  todo
		ioMainListGet: '/rrj/IoMain/ioMainListGet', //进出单列表  todo
		ioMainListAudit: '/rrj/IoMain/ioMainListAudit', //审核   todo
		ioMainListUnAudit: '/rrj/IoMain/ioMainListUnAudit', //反审   todo
		ioMainListDel: '/rrj/IoMain/ioMainListDel', //删除   todo
		subjectWareGet: '/rrj/Common/subjectWareGet',  //通用主体仓库   todo
		subjectGet: '/rrj/Api/subjectGet', //查询申请主体   todo
		resStateGet: '/rrj/Common/resStateGet', //通用资源明细    todo
		ioJsAuditGet: '/rrj/IoJs/ioJsAuditGet',  //结算单审核列表   todo
		ioJsAuditDel: '/rrj/IoJs/ioJsAuditDel',  //结算单删除   todo
		ioJsAuditCheck: '/rrj/Api/ioJsAuditCheck',  //结算单审核   todo
		ioJsAuditUnCheck: '/rrj/IoJs/ioJsAuditUnCheck',  //结算单反审   todo
		ioJsGet: '/rrj/IoJs/ioJsGet', //结算单新增列表    todo
		ioJsCreate: '/rrj/Api/ioJsCreate', //结算单新增  todo
		waitTaskCount: '/system/Workflow/waitTaskCount', //待办任务数量   todo
		waitTaskGet: '/rrj/Api/waitTaskGet', //待办任务列表
		histTaskGet: '/rrj/Api/histTaskGet', //已办任务列表
		selfOrderGet: '/rrj/Api/selfOrderGet', //我的流程列表
		userInfo: '/rrj/Api/userinfo', //我的用户信息
		loginOut: '/rrj/Api/unbind', //退出登陆解除绑定
		moduleGet: '/rrj/Api/moduleGet', //消息模块
		moduleContentGet: '/rrj/Api/moduleContentGet'  //指定模块消息列表
	},
	Const: {
		//进出方式
		inOutType: [
			{value: '', text: '请选择'},
			{value: '001', text: '购销类'},
			{value: '002', text: '预清算类'},
			{value: '003', text: '借贷类'},
			{value: '004', text: '投资类'},
			{value: '005', text: '代理清算类'},
			{value: '006', text: '调拨类'},
			{value: '007', text: '盘盈盘亏类'},
			{value: '008', text: '摊销出库'},
			{value: '009', text: '消耗出库'},
			{value: '010', text: '捐赠类'},
			{value: '049', text: '生产性进出'},
			{value: '050', text: '其他不定向类'},
			{value: '051', text: '期初类'},
			{value: '052', text: '押金类'},
			{value: 'IO000', text: '清算类'},
		],
		//资源类型
		resZY: [
			{value: '', text: '全部'},
			{value: '1', text: '货币类'},
			{value: '2', text: '物资类'},
			{value: '3', text: '收支类'},
			{value: '4', text: '往来类'},
		]
	},
	isNull: function(value){
		return !value
	},
	getQueryString: function(name) {
		var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
		var r = window.location.search.substr(1).match(reg);
		if (r != null) {
			return decodeURIComponent(r[2]);
		}
		return null;
	},
	formatMoney: function(number, decimals, dec_point, thousands_sep) {
		/*
       * 参数说明：
       * number：要格式化的数字
       * decimals：保留几位小数
       * dec_point：小数点符号
       * thousands_sep：千分位符号
       * */
		decimals = decimals || 2;
		dec_point = dec_point || '.';
		thousands_sep = thousands_sep || ','
		number = (number + '').replace(/[^0-9+-Ee.]/g, '');
		var n = !isFinite(+number) ? 0 : +number,
			prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
			sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
			dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
			s = '',
			toFixedFix = function (n, prec) {
				var k = Math.pow(10, prec);
				return '' + Math.ceil(n * k) / k;
			};

		    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
		    var re = /(-?\d+)(\d{3})/;
		    while (re.test(s[0])) {
			         s[0] = s[0].replace(re, "$1" + sep + "$2");
			     }

		    if ((s[1] || '').length < prec) {
			         s[1] = s[1] || '';
			         s[1] += new Array(prec - s[1].length + 1).join('0');
			     }
		    return s.join(dec);
	},
	request: function(url, data, callback){
		$.ajax(url1 + url,{
			contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
			data: $.extend(data, {accessid: window.localStorage.accessid || ''}),
			type: 'POST',
			success: (data) => {
				// console.log(data)
				if(data.hasError){
					mui.alert(data.error);
				} else{
					callback(data)
				}
			}
		})
	}
};

//判断字符创是否为空
function isNull(value){
	return ((typeof(value) == "undefined") || (value === null) || (value === ""));
}

